<template>
  <div class="workflow-designer">
    <!-- 顶部工具栏 -->
    <div class="header-bar">
      <div class="header-left">
        <span class="page-id">&lt; 22</span>
      </div>
      <div class="header-center">
        <div class="tool-button">
          <el-icon><ZoomIn /></el-icon>
          <span>缩放</span>
        </div>
        <div class="tool-button">
          <el-icon><Warning /></el-icon>
          <span>全局错误</span>
        </div>
        <div class="tool-button">
          <el-icon><Refresh /></el-icon>
          <span>开始调试</span>
        </div>
        <div class="tool-button">
          <el-icon><Document /></el-icon>
          <span>保存</span>
        </div>
        <div class="tool-button">
          <el-icon><Delete /></el-icon>
          <span>删除</span>
        </div>
        <div class="tool-button" @click="exitDesigner">
          <el-icon><ArrowRight /></el-icon>
          <span>退出</span>
        </div>
      </div>
      <div class="header-right">
        <div class="tool-button">
          <el-icon><QuestionFilled /></el-icon>
          <span>帮助</span>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 中央画布 -->
      <div class="canvas-area">
        <div class="workflow-canvas">
          <!-- REST API 节点 -->
          <div class="workflow-node rest-api-node">
            <div class="node-add-btn top">+</div>
            <div class="node-content">
              <div class="node-icon">
                <el-icon><Connection /></el-icon>
              </div>
              <div class="node-label">REST API</div>
            </div>
            <div class="node-add-btn bottom">+</div>
          </div>
          
          <!-- 连接箭头 -->
          <div class="workflow-arrow">
            <el-icon><ArrowDown /></el-icon>
          </div>
          
          <!-- Excel 节点 -->
          <div class="workflow-node excel-node" @click="selectNode('excel')">
            <div class="node-add-btn top">+</div>
            <div class="node-content">
              <div class="node-icon excel-icon">
                <img src="../assets/excel.png" alt="Excel" style="width: 24px; height: 24px;" />
              </div>
              <div class="node-label">文本文档</div>
            </div>
            <div class="node-add-btn bottom">+</div>
          </div>
        </div>
      </div>
      <div class="splitter" @mousedown="startDrag"></div>
      <!-- 右侧设置面板 -->
      <div class="settings-panel" :style="{ width: settingsPanelWidth + 'px' }">
        <div class="panel-header">
          <span class="panel-title">&gt; Excel设置</span>
        </div>
        <div class="panel-content">
          <el-form label-width="88px" size="small">
            <el-form-item label="描述">
              <el-input placeholder="请输入描述" />
            </el-form-item>
            <el-form-item label="连接" required>
              <el-select v-model="selectedConnection" placeholder="请选择连接" style="width: 100%;">
                <el-option label="新建-Excel" value="new-excel" />
                <el-option label="Excel-商品列表" value="excel-goods" />
                <el-option label="Excel-订单列表" value="excel-orders" />
              </el-select>
            </el-form-item>
            <el-form-item label="动作" required>
              <el-select v-model="selectedAction" placeholder="请选择动作" style="width: 100%;" :disabled="actionDisabled">
                <el-option label="查询" value="query" />
                <el-option label="统计数量" value="count" />
              </el-select>
            </el-form-item>
            <el-form-item :label="''" v-if="selectedConnection" required>
              <template #label>
                <span style="display: inline-flex; align-items: center;">
                  工作表
                  <el-tooltip content="选择一个需要查询的工作表" placement="top">
                    <el-icon style="margin-left: 4px; color: #909399; font-size: 16px; vertical-align: middle; display: inline-flex; align-items: center;">
                      <QuestionFilled />
                    </el-icon>
                  </el-tooltip>
                </span>
              </template>
              <el-select v-model="worksheet" placeholder="请选择工作表" style="width: 100%;">
                <el-option label="Sheet1" value="Sheet1" />
                <el-option label="Sheet2" value="Sheet2" />
                <el-option label="Sheet3" value="Sheet3" />
              </el-select>
            </el-form-item>
            <el-form-item label="数据响应格式" v-if="selectedConnection">
              <el-select v-model="responseFormat" placeholder="请选择格式" style="width: 100%;">
                <el-option label="JSON" value="json" />
                <el-option label="XML" value="xml" />
              </el-select>
            </el-form-item>
            

          </el-form>
          
          <!-- 字段配置部分 -->
          <div class="fields-config-section">
            <el-card class="group-card fields-card" shadow="never">
              <el-tabs v-model="fieldsSubTab" class="fields-subtab">
                <el-tab-pane label="选择字段" name="select-fields" v-if="selectedAction !== 'count'">
                  <el-table :data="fields" border class="fields-table" style="margin-bottom: 0;">
                    <el-table-column prop="name" label="字段名称" min-width="120" />
                    <el-table-column prop="type" label="类型" min-width="100" />
                    <el-table-column label="返回参数名称" min-width="140">
                      <template #default="scope">
                        <el-input v-model="scope.row.returnName" placeholder="请输入返回参数名称" size="small" />
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" min-width="150">
                      <template #default="scope">
                        <el-button :icon="ArrowUp" @click="moveFieldUp(scope.$index)" link size="small" style="color: #409EFF;" class="op-btn" />
                        <el-button :icon="ArrowDown" @click="moveFieldDown(scope.$index)" link size="small" style="color: #409EFF;" class="op-btn" />
                        <el-button :icon="Delete" @click="removeField(scope.$index)" link size="small" style="color: #f56c6c;" title="删除" class="op-btn" />
                      </template>
                    </el-table-column>
                  </el-table>
                </el-tab-pane>
                <el-tab-pane label="条件配置" name="condition">
                  <el-tabs v-model="conditionSubTab" class="condition-subtab">
                    <el-tab-pane label="过滤条件" name="filter">
                      <el-table :data="conditions" class="condition-table">
                        <el-table-column prop="preLink" label="前连接" min-width="100">
                          <template #default="scope">
                            <el-select v-model="scope.row.preLink" placeholder="请选择" size="small" style="width: 100%;">
                              <el-option label="无" value="无" />
                              <el-option label="(" value="(" />
                              <el-option label="and" value="and" />
                              <el-option label="or" value="or" />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column prop="field" label="字段名称" min-width="120">
                          <template #default="scope">
                            <el-select v-model="scope.row.field" placeholder="请选择" size="small" style="width: 100%;" @change="updateFieldType(scope.$index)">
                              <el-option label="Sheet1.姓名" value="Sheet1.姓名" />
                              <el-option label="Sheet1.年龄" value="Sheet1.年龄" />
                              <el-option label="Sheet1.出生日期" value="Sheet1.出生日期" />
                              <el-option label="Sheet1.身高" value="Sheet1.身高" />
                              <el-option label="Sheet1.成绩" value="Sheet1.成绩" />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column prop="type" label="字段类型" min-width="100" />
                        <el-table-column prop="op" label="操作符" min-width="100">
                          <template #default="scope">
                            <el-select v-model="scope.row.op" placeholder="请选择" size="small" style="width: 100%;">
                              <el-option label="=" value="=" />
                              <el-option label=">" value=">" />
                              <el-option label=">=" value=">=" />
                              <el-option label="<" value="<" />
                              <el-option label="<=" value="<=" />
                              <el-option label="!=" value="!=" />
                              <el-option label="in" value="in" />
                              <el-option label="not in" value="not in" />
                              <el-option label="like" value="like" />
                              <el-option label="not like" value="not like" />
                              <el-option label="is null" value="is null" />
                              <el-option label="is not null" value="is not null" />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column prop="param" label="请求参数名称/常量" min-width="140">
                          <template #default="scope">
                            <el-input v-model="scope.row.param" placeholder="请输入" size="small" />
                          </template>
                        </el-table-column>
                        <el-table-column prop="postLink" label="后连接" min-width="100">
                          <template #default="scope">
                            <el-select v-model="scope.row.postLink" placeholder="请选择" size="small" style="width: 100%;">
                              <el-option label="无" value="无" />
                              <el-option label="and" value="and" />
                              <el-option label="or" value="or" />
                              <el-option label=")and" value=")and" />
                              <el-option label=")or" value=")or" />
                              <el-option label=")" value=")" />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column label="操作" min-width="210">
                          <template #header>
                            <span>操作</span>
                          </template>
                          <template #default="scope">
                            <el-button :icon="Plus" @click="addCondition(scope.$index)" link size="small" title="新增一行" class="op-btn" />
                            <el-button :icon="Delete" @click="removeCondition(scope.$index)" link size="small" style="color:#f56c6c;" title="删除" class="op-btn" />
                            <el-button :icon="ArrowUp" @click="moveConditionUp(scope.$index)" link size="small" class="op-btn" />
                            <el-button :icon="ArrowDown" @click="moveConditionDown(scope.$index)" link size="small" class="op-btn" />
                          </template>
                        </el-table-column>
                      </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="排序设置" name="sort">
                      <el-table :data="sortConditions" class="sort-table">
                        <el-table-column prop="sequence" label="序列" min-width="80">
                          <template #default="scope">
                            {{ scope.$index + 1 }}
                          </template>
                        </el-table-column>
                        <el-table-column prop="field" label="排序字段" min-width="150">
                          <template #default="scope">
                            <el-select v-model="scope.row.field" placeholder="请选择排序字段" size="small" style="width: 100%;">
                              <el-option label="Sheet1.姓名" value="Sheet1.姓名" />
                              <el-option label="Sheet1.年龄" value="Sheet1.年龄" />
                              <el-option label="Sheet1.出生日期" value="Sheet1.出生日期" />
                              <el-option label="Sheet1.身高" value="Sheet1.身高" />
                              <el-option label="Sheet1.成绩" value="Sheet1.成绩" />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column prop="method" label="排序方式" min-width="120">
                          <template #default="scope">
                            <el-select v-model="scope.row.method" placeholder="请选择排序方式" size="small" style="width: 100%;">
                              <el-option label="ASC" value="ASC" />
                              <el-option label="DESC" value="DESC" />
                            </el-select>
                          </template>
                        </el-table-column>
                        <el-table-column label="操作" min-width="150">
                          <template #default="scope">
                            <el-button :icon="Plus" @click="addSort" link size="small" title="新增" class="op-btn" />
                            <el-button :icon="ArrowUp" @click="moveSortUp(scope.$index)" link size="small" title="上移" class="op-btn" />
                            <el-button :icon="ArrowDown" @click="moveSortDown(scope.$index)" link size="small" title="下移" class="op-btn" />
                            <el-button :icon="Delete" @click="removeSort(scope.$index)" link size="small" style="color:#f56c6c;" title="删除" class="op-btn" />
                          </template>
                        </el-table-column>
                      </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="分页设置" name="pagination">
                      <el-form :model="paginationForm" label-width="140px" class="pagination-form">
                        <el-form-item label="是否允许分页查询">
                          <el-switch v-model="paginationForm.enablePagination" />
                        </el-form-item>
                        <el-form-item label="分页参数名称">
                          page
                        </el-form-item>
                        <el-form-item label="返回数量参数名">
                          pageSize
                        </el-form-item>
                      </el-form>
                    </el-tab-pane>
                  </el-tabs>
                </el-tab-pane>
              </el-tabs>

            </el-card>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
import { useRouter } from 'vue-router'
import { 
  ZoomIn, 
  Warning, 
  Refresh, 
  Document, 
  Delete, 
  ArrowRight, 
  QuestionFilled,
  Connection,
  ArrowDown,
  Plus
} from '@element-plus/icons-vue'
import emitter from '../event-bus'

const resultCount = ref('10')
const settingsPanelWidth = ref(840)
let dragging = false
let startX = 0
let startWidth = 840
function startDrag(e) {
  dragging = true
  startX = e.clientX
  startWidth = settingsPanelWidth.value
  document.body.style.cursor = 'col-resize'
}
function onDrag(e) {
  if (dragging) {
    const minWidth = 440
    const maxWidth = 1800
    const delta = startX - e.clientX
    let newWidth = startWidth + delta
    newWidth = Math.min(Math.max(newWidth, minWidth), maxWidth)
    settingsPanelWidth.value = newWidth
  }
}
function stopDrag() {
  dragging = false
  document.body.style.cursor = ''
}
onMounted(() => {
  window.addEventListener('mousemove', onDrag)
  window.addEventListener('mouseup', stopDrag)
})
onBeforeUnmount(() => {
  window.removeEventListener('mousemove', onDrag)
  window.removeEventListener('mouseup', stopDrag)
})

const selectedConnection = ref('')
const actionDisabled = computed(() => !selectedConnection.value)

const selectedAction = ref('query')

const responseFormat = ref('json')

const worksheet = ref('')



const selectNode = (nodeType) => {
  console.log('Selected node:', nodeType)
}

const router = useRouter()
const exitDesigner = () => {
  router.push('/')
}

const testSelect = ref('')
const currentPage = ref(1)

// 字段配置相关变量
const fieldsSubTab = ref('select-fields')
const conditionSubTab = ref('filter')
const collapseActive = ref(['result'])
const resultTab = ref('sql')

// 字段数据
const fields = ref([
  { name: 'Sheet1.姓名', type: 'VARCHAR', comment: '', agg: '', returnName: '' },
  { name: 'Sheet1.年龄', type: 'Integer', comment: '', agg: '', returnName: '' },
  { name: 'Sheet1.出生日期', type: 'VARCHAR', comment: '', agg: '', returnName: '' },
  { name: 'Sheet1.身高', type: 'Double', comment: '', agg: '', returnName: '' },
  { name: 'Sheet1.成绩', type: 'Double', comment: '', agg: '', returnName: '' }
])

// 条件配置数据
const conditions = ref([
  { preLink: '无', field: '', type: '', comment: '', op: '', param: '', postLink: '无' }
])

// 排序配置数据
const sortConditions = ref([
  { sequence: 1, field: 'Sheet1.姓名', method: 'ASC' },
  { sequence: 2, field: 'Sheet1.年龄', method: 'DESC' }
])

// 分页配置数据
const paginationForm = ref({
  enablePagination: false,
  pageParamName: 'page',
  pageSizeParamName: 'pageSize'
})

// 字段操作函数
function moveFieldUp(idx) {
  if (idx > 0) {
    const arr = fields.value
    const t = arr[idx]; arr[idx] = arr[idx-1]; arr[idx-1] = t
  }
}

function moveFieldDown(idx) {
  if (idx < fields.value.length - 1) {
    const arr = fields.value
    const t = arr[idx]; arr[idx] = arr[idx+1]; arr[idx+1] = t
  }
}

function removeField(idx) {
  fields.value.splice(idx, 1)
}

// 条件操作函数
function updateFieldType(index) {
  const field = conditions.value[index].field;
  const fieldType = fields.value.find(f => f.name === field)?.type;
  if (fieldType) {
    conditions.value[index].type = fieldType;
  } else {
    conditions.value[index].type = '';
  }
}

function moveConditionUp(idx) {
  if (idx > 0) {
    const arr = conditions.value
    const t = arr[idx]; arr[idx] = arr[idx-1]; arr[idx-1] = t
  }
}

function moveConditionDown(idx) {
  if (idx < conditions.value.length - 1) {
    const arr = conditions.value
    const t = arr[idx]; arr[idx] = arr[idx+1]; arr[idx+1] = t
  }
}

function removeCondition(idx) {
  conditions.value.splice(idx, 1)
}

function addCondition(idx) {
  const newRow = { preLink: '无', field: '', type: '', comment: '', op: '', param: '', postLink: '无' }
  if (typeof idx === 'number') {
    conditions.value.splice(idx + 1, 0, newRow)
  } else {
    conditions.value.push(newRow)
  }
}

// 排序操作函数
function moveSortUp(idx) {
  if (idx > 0) {
    const arr = sortConditions.value
    const t = arr[idx]; arr[idx] = arr[idx-1]; arr[idx-1] = t
  }
}

function moveSortDown(idx) {
  if (idx < sortConditions.value.length - 1) {
    const arr = sortConditions.value
    const t = arr[idx]; arr[idx] = arr[idx+1]; arr[idx+1] = t
  }
}

function removeSort(idx) {
  sortConditions.value.splice(idx, 1)
}

function addSort() {
  const newRow = { sequence: sortConditions.value.length + 1, field: '', method: 'ASC' }
  sortConditions.value.push(newRow)
}

// SQL预览计算属性
const sqlPreview = computed(() => {
  const cols = fields.value.map(f => '`' + f.name + '`').join(',')
  let sql = `SELECT ${cols} FROM Sheet1`
  
  // 添加过滤条件
  const validConditions = conditions.value.filter(c => c.field && c.op && c.param)
  if (validConditions.length > 0) {
    sql += ' WHERE '
    const conditionsStr = validConditions.map(c => {
      let condition = ''
      if (c.preLink && c.preLink !== '无') {
        condition += c.preLink + ' '
      }
      condition += `\`${c.field}\` ${c.op} '${c.param}'`
      if (c.postLink && c.postLink !== '无') {
        condition += ' ' + c.postLink
      }
      return condition
    }).join(' ')
    sql += conditionsStr
  }
  
  // 添加排序条件
  const validSorts = sortConditions.value.filter(s => s.field && s.method)
  if (validSorts.length > 0) {
    sql += ' ORDER BY '
    const sortStr = validSorts.map(s => `\`${s.field}\` ${s.method}`).join(', ')
    sql += sortStr
  }
  
  return sql
})

// 监听操作类型变化，自动切换选项卡
watch(() => selectedAction.value, (newVal) => {
  if (newVal === 'count') {
    fieldsSubTab.value = 'condition'
  } else {
    fieldsSubTab.value = 'select-fields'
  }
})
</script>

<style scoped>
.workflow-designer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f5f6fa;
  /* 不加z-index */
}

/* 顶部工具栏 */
.header-bar {
  height: 60px;
  background: #2c3e50;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-left .page-id {
  font-size: 16px;
  font-weight: 500;
}

.header-center {
  display: flex;
  gap: 20px;
}

.tool-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.tool-button:hover {
  background: rgba(255,255,255,0.1);
}

.tool-button .el-icon {
  font-size: 18px;
  margin-bottom: 2px;
}

.tool-button span {
  font-size: 12px;
}

/* 主要内容区域 */
.main-content {
  display: flex;
  flex: 1;
}

/* 中央画布 */
.canvas-area {
  flex: 1;
  background: white;
  overflow-y: auto;
}

.workflow-canvas {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px;
  background-image: radial-gradient(circle, #e0e0e0 1px, transparent 1px);
  background-size: 20px 20px;
}

.workflow-node {
  position: relative;
  margin: 20px 0;
  cursor: pointer;
}

.node-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: white;
  border: 2px solid #409eff;
  border-radius: 8px;
  padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: all 0.2s;
}

.node-content:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.node-icon {
  margin-bottom: 8px;
  font-size: 24px;
  color: #409eff;
}

.excel-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.node-label {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.node-add-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  background: #409eff;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.2s;
}

.node-add-btn:hover {
  background: #337ecc;
}

.node-add-btn.top {
  top: -10px;
}

.node-add-btn.bottom {
  bottom: -10px;
}

.workflow-arrow {
  margin: 10px 0;
  color: #409eff;
  font-size: 20px;
}

/* 右侧设置面板 */
.settings-panel {
  background: white;
  border-left: 1px solid #e4e7ed;
  display: flex;
  flex-direction: column;
  transition: width 0.1s;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e4e7ed;
  background: #fafbfc;
}

.panel-title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.panel-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.error-input :deep(.el-input__wrapper) {
  border-color: #f56c6c;
}

.error-message {
  color: #f56c6c;
  font-size: 12px;
  margin-top: 4px;
}

.splitter {
  width: 6px;
  cursor: col-resize;
  background: #e4e7ed;
  z-index: 2;
  transition: background 0.2s;
}

.splitter:hover {
  background: #bfcbd9;
}
:deep(.el-select-dropdown) {
  z-index: 99999 !important;
  position: fixed !important;
  left: 0 !important;
  top: 0 !important;
}
.condition-table {
  width: 100%;
  display: table;
  border-collapse: separate;
  border-spacing: 0 4px;
}
.condition-header {
  font-weight: 500;
  color: #666;
  background: #f7f7f7;
}
.condition-row {
  display: table-row;
}
.condition-cell {
  display: table-cell;
  padding: 4px 8px 4px 0;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.condition-header .condition-cell {
  border-bottom: 2px solid #e4e7ed;
  background: #f7f7f7;
}
.add-btn {
  color: #409eff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add-btn:hover {
  color: #337ecc;
}
:deep(.el-form-item) {
  min-height: 38px;
  align-items: center;
}
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
  min-height: 30px;
  font-size: 15px;
}
:deep(.el-input__wrapper),
:deep(.el-select .el-input__wrapper),
:deep(.el-select__selected-item) {
  height: 32px !important;
  min-height: 32px !important;
  line-height: 32px !important;
  box-sizing: border-box;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}
:deep(.el-input__inner) {
  height: 32px !important;
  min-height: 32px !important;
  line-height: 32px !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

/* 字段配置样式 */
.fields-config-section {
  margin-top: 20px;
}

.fields-topbar {
  background: #f8f9fb;
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
}

.fields-topbar-btn {
  font-size: 12px;
}

.fields-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.fields-tip {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 4px;
  padding: 8px 12px;
  margin-bottom: 16px;
  font-size: 12px;
  color: #0369a1;
}

.fields-table {
  font-size: 14px;
}

.fields-subtab {
  margin-bottom: 0;
}

.fields-subtab :deep(.el-tabs__item) {
  font-size: 14px !important;
  font-weight: normal !important;
}

.condition-subtab {
  margin-bottom: 0;
}

.condition-subtab :deep(.el-tabs__item) {
  font-size: 14px !important;
  font-weight: normal !important;
}

.condition-toolbar {
  background: #f8f9fb;
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
}

.sort-table {
  background: #fafbfc;
  border-radius: 4px;
  font-size: 14px;
  --el-table-border-color: #f0f0f0;
  --el-table-header-bg-color: #f8f9fb;
  --el-table-row-hover-bg-color: #f4f8fa;
  --el-table-header-font-weight: normal;
}

.sort-table :deep(.el-table__header th) {
  font-size: 14px;
  font-weight: normal;
  background: #f8f9fb;
  color: #666;
}

.sort-table :deep(.el-table__cell),
.sort-table :deep(td) {
  text-align: center;
  vertical-align: middle;
}

.sort-table :deep(.el-table__body tr) {
  background: #fff;
}

.sort-table :deep(.el-table__body td) {
  border-right: none !important;
}

.sort-table :deep(.el-table__row) {
  transition: background 0.2s;
}

.sort-table :deep(.el-table__row:hover) {
  background: #f4f8fa !important;
}

.pagination-form {
  margin-top: 16px;
}

.fields-collapse {
  margin-top: 18px;
}

.sql-preview {
  background: #f8f9fb;
  border: 1px solid #e4e7ed;
  border-radius: 4px;
  padding: 12px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #333;
  white-space: pre-wrap;
  word-break: break-all;
}

.result-placeholder {
  color: #909399;
  text-align: center;
  padding: 32px;
  font-size: 14px;
}

.op-btn {
  height: 24px;
  line-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.op-btn:not(:last-child) {
  margin-right: 6px;
}
</style> 